package com.lmh.controller;

import com.github.pagehelper.PageInfo;
import com.lmh.entity.Tag;
import com.lmh.service.TagService;
import com.lmh.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/tag")
public class TagController {

    @Autowired
    private TagService tagService;

    @PostMapping("/create")
    public Result create(@RequestBody Tag tag) {
        tagService.create(tag);
        return Result.ok(tag);
    }

    @PostMapping("/delete")
    public Result delete(Integer id) {
        tagService.delete(id);
        return Result.ok();
    }

    @PostMapping("/update")
    public Result update(@RequestBody Tag tag) {
        tagService.update(tag);
        return Result.ok(tag);
    }

    @RequestMapping("/query")
    public Map<String, Object> query(@RequestBody Tag tag) {
        PageInfo<Tag> queries = tagService.query(tag);
        return Result.ok(queries);
    }

    @PostMapping("/all")
    public Result all() {
        return Result.ok(tagService.all());
    }

    @RequestMapping("/detail")
    public Result detail(Integer id) {
        Tag tag = tagService.detail(id);
        return Result.ok(tag);
    }

    @RequestMapping("/count")
    public Result count(@RequestBody Tag tag) {
        Integer count = tagService.count(tag);
        return Result.ok(count);
    }
}
